package com.wy.controller;

import com.wy.common.BaseCommonController;
import com.wy.common.exception.BizException;
import com.wy.constant.CodeConst;
import com.wy.constant.SpringMVCConst;
import com.wy.protocol.ERRORCODE;
import com.wy.util.WordUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.net.URLEncoder;

@Controller
@Scope(SpringMVCConst.SCOPE)
@RequestMapping("/word")
public class WordController extends BaseCommonController {
	
	/**
	 * 异步验证登录
	 */
	@RequestMapping(value = "/doFilter", method = RequestMethod.GET)
	@ResponseBody
	public String doFilter(@RequestParam(value="word",required=false)String word) throws Exception{
		if(StringUtils.isEmpty(word)){
			return null;
		}
		String keyword = null;
		try {
			keyword = WordUtil.doFilter(URLEncoder.encode(word, CodeConst.UTF_8));
		}catch(Exception e){
			throw new BizException(ERRORCODE.FAIL.getCode(), ERRORCODE.FAIL.getMessage());
		}
		return keyword;
	}
	
}
